package com.zzzyh.forumsystemclient.cotroller;


import com.zzzyh.forumsystemclient.common.AppResult;
import com.zzzyh.forumsystemclient.model.Friend;
import com.zzzyh.forumsystemclient.model.Message;
import com.zzzyh.forumsystemclient.services.IMessageSercive;
import com.zzzyh.forumsystemclient.services.IUser_UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private IUser_UserService user_userService;
    @Autowired
    private IMessageSercive messageSercive;
    @RequestMapping("/getContacts")
    public AppResult<List<Friend>> getContacts(Long userId){
        return AppResult.success(user_userService.getContacts(userId));
    }

    @RequestMapping("/getFollowers")
    public AppResult<List<Friend>> getFollowers(Long userId){
        return AppResult.success(user_userService.getFollowers(userId));
    }

    @RequestMapping("/getStrangers")
    public AppResult<List<Friend>> getStrangers(Long userId){
        return AppResult.success(user_userService.getStrangers(userId));
    }

    @RequestMapping("/getChatMessages")
    public AppResult<List<Message>> getChatMessages(Long user1, Long user2){
        log.info("getChatMessages: user1: {}, user2: {}", user1, user2);
        return AppResult.success(messageSercive.getChatMessages(user1, user2));
    }

    @RequestMapping("/addMessage")
    public AppResult<Void> addMessage(@RequestBody Message message){
        log.info("addMessage: {}", message);
        messageSercive.addMessage(message);
        return AppResult.success();
    }
}
